from __future__ import annotations

from dataclasses import dataclass


@dataclass
class RepresentativeSpan:
    span_m: float
    note: str


def compute_representative_span(spans_m: list[float]) -> RepresentativeSpan:
    """代表档距：l_r = Σ(l_i^3) / Σ(l_i^2)。"""

    if not spans_m:
        return RepresentativeSpan(span_m=0.0, note="空输入")
    s3 = sum([l ** 3 for l in spans_m])
    s2 = sum([l ** 2 for l in spans_m])
    return RepresentativeSpan(span_m=s3 / max(1e-9, s2), note="GB50545常用计算式")


